<?php
/**
* Cong ty TNHH Tin Hoc Phan Anh Huy
* Website: www.phananhhuy.vn
* Hotline: 0939739539
*/
	defined('_JEXEC') or die ('Direct Access is not allowed');
	$allweblinks = intval($params->get('allweblinks',0));
	$golabel = $params->get('buttonname','Go');
	$blank = intval($params->get('firstblank',0));
	$custom = $params->get('firsttext','');
	$separator = $params->get('separator','');
	$image = $params->get('buttonimage','-1');
	$catname = strtolower($params->get('catname','jumplinks'));
	$autodirect = intval($params->get('autodirect',0));
	if (isset($_POST['submit']) || isset($_POST['submit_x']))
	{
		$link = $_POST['add'];
		$target = $params->get('target','parent');
		switch ($target)
		{
		
		case 'parent':
			echo "<meta http-equiv='Refresh' content='0;URL=" .$link. "' />";
			break;
		case 'newwith':
			echo "<meta http-equiv='Refresh' content='0;URL=" .$_SERVER['REQUEST_URI']. "' />";
			echo "<script type='text/javascript'>window.open('".$link."');</script>";
			break;
		case 'newwithout':
			echo "<meta http-equiv='Refresh' content='0;URL=" .$_SERVER['REQUEST_URI']. "' />";
			echo "<script type='text/javascript'>window.open('".$link."','',config='toolbar=no');</script>";
			break;
		
		
		}
		exit();
	}
	
		$db = JFactory::getDBO();
		$cat = "lower(jc.title) = '".$catname."' AND ";
		if ($allweblinks == '1')
			$cat = '';
		$order = $params->get('order',0);
		
		switch ($order)
		{
			case 0:
				$orderStr = "ordering";
				break;
			case 1:
				$orderStr = "j.title ASC";
				break;
			case 2:
				$orderStr = "j.title DESC";
		}
		$query = "SELECT j.* FROM #__weblinks j inner join #__categories jc on j.catid = jc.id where $cat  j.published='1' AND jc.published='1' ORDER BY $orderStr";
		$db->setquery($query);
		$rows=$db->loadObjectList();
		error_reporting(E_ERROR); 
		$url = $_SERVER['SERVER_URI'];
		echo "<div class='link'>";
		foreach ($rows as $row)
		{
			echo "<div class='link_a'>";
			echo "<a href='".$row->url."' target='_blank' >". $row->title . "</a>";
			echo "</div>";
		}
		echo "</div>";
		/* echo "<form action='" . $url . "' method='post' >";
		echo "<p>";

			echo "<select name='add' id='add'";
			if ($autodirect == 1) 
				{
					 echo " onChange='this.form.elements";
					 echo "[\"submit\"].click();' >";
				}
			else
			{
				echo " >";
			}		
			echo "<option value=''>-- Select  Weblink --</option>";
		if ($blank == '1')
			echo "<option value='' />";
		if ($custom != '')
		{
			echo "<option value='' />".$custom;
			if ($separator != '')
				echo "<option value='' >".str_repeat($separator,strlen($custom))."</option>";
		}

		foreach ($rows as $row)
		{
			echo "<option value='" .$row->url. "' > ". $row->title . "</option>";
		}
		echo "</select>";
	   
			if ($autodirect == 1)
			{
				$style="style='visibility:hidden'";
			}
			if ($image !=-1 )
			{
				if ($autodirect ==1)
					echo "<input type='submit' ".$style." id='submit' name='submit' value='".$golabel."' />";
				$image = 'images/stories/'.$image;
				echo "<input type='image' " .$style." src='".$image."' id='submit' name='submit' alt='".$golabel."' />";
			}
			else
			{
				
				echo "<input type='submit' ".$style." id='submit' name='submit' value='".$golabel."' />";
			}


		echo  "</p></form>"; */
	
 ?>